package il.ac.bgu.cs.heuristics.ui;

import static il.ac.bgu.cs.heuristics.utils.MathUtils.average;
import il.ac.bgu.cs.heuristics.utils.Pair;

import java.awt.Dimension;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ErrorDialog extends JDialog{
	private final static String DIALOG_TITLE = "Error";
	private final static Pair<Integer> DIALOG_DIMENSIONS = new Pair<Integer>(
	        300, 160);

	public ErrorDialog(String errorMessage) {
		super();
		setModalityType(ModalityType.APPLICATION_MODAL);

		final int dialogWidth = DIALOG_DIMENSIONS.getFirst();
		final int dialogHeight = DIALOG_DIMENSIONS.getSecond();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLocationRelativeTo(null);
		setSize(dialogWidth, dialogHeight);
		final Dimension size = getToolkit().getScreenSize();
		setLocation(average(size.width, -dialogWidth), average(size.height,
		        -dialogHeight));
		setTitle(DIALOG_TITLE);
		final JPanel panel = new JPanel();
		getContentPane().add(panel);

		panel.setLayout(null);

		final JLabel msg = new JLabel(errorMessage);
		msg.setBounds(10, 10, 300, 100);

		panel.add(msg);
	}

}
